import javax.swing.*;
import java.awt.*;

/**
 * Created by mary on 16.03.14.
 */
public class MaryPainter {
    private Graphics graphics;

    public MaryPainter() {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(600, 600);
        frame.setLocation(900, 300);
        frame.setVisible(true);
        frame.setContentPane(new JPanel() {
            @Override
            public void paint(Graphics g) {
                super.paint(g);
                graphics = g;
                draw();
            }
        });
    }

    public static void main(String[] args) {
        new MaryPainter();
    }

    //---------------------------------------------------------
    //---------------------------------------------------------

    void drawDot(int x, int y) {
        graphics.setColor(Color.BLACK);
        graphics.drawLine(x, y, x, y);
    }

    void drawDot(int x, int y, Color color) {
        graphics.setColor(color);
        graphics.drawLine(x, y, x, y);
    }

    //---------------------------------------------------------


    void draw() {
        drawGrid123(0, 0, 10);

//        window(50, 0);


        rectengel(0, 0, 600, 600, Color.green);
        rectengel(0, 0, 600, 215, Color.blue);

        rectengel(25, 50, 115, 20, Color.white);
        rectengel(50, 70, 115, 20, Color.white);

//        rectengel(450, 70, 50, 50, Color.orange);

        disc(450, 70, 50, Color.orange);


        house(175, 100, 200, 270);
        fence(100, 315, 20, 100, 16, Color.MAGENTA);



    }

    private void window(int x0, int y0) {

        for (int i = 100; i < 200; i = i + 1) {
            drawDot(x0 + i, y0 + 300 - i);
        }


        for (int i = 200; i < 300; i = i + 1) {
            drawDot(x0 + i, y0 + i - 100);
        }

        for (int x = 100; x < 300; x++) {
            drawDot(x0 + x, y0 + 200);

        }

        for (int y = 260; y < 310; y++) {
            drawDot(x0 + 160, y0 + y);

        }

        for (int y = 260; y < 310; y++) {
            drawDot(x0 + 230, y0 + y);

        }

        for (int x = 160; x < 230; x++) {
            drawDot(x0 + x, y0 + 260);

        }

        for (int x = 160; x < 230; x++) {
            drawDot(x0 + x, y0 + 310);

        }

        for (int x = 160; x < 230; x++) {
            drawDot(x0 + x, y0 + 285);

        }

        for (int y = 260; y < 310; y++) {
            drawDot(x0 + 195, y0 + y);

        }

        for (int y = 100; y < 140; y++) {
            drawDot(x0 + 240, y0 + y);

        }

        for (int y = 100; y < 160; y++) {
            drawDot(x0 + 260, y0 + y);

        }

        for (int x = 240; x < 260; x++) {
            drawDot(x0 + x, y0 + 100);

        }

        for (int x = 0; x < 600; x++) {
            drawDot(x, 300);

        }


    }


    private void drawGrid123(int x, int y, int size) {
        for (int i = 0; i < 600; i++) {
            for (int j = 0; j < 600; j++) {
                drawDot(x + i * size, y + j * size);
            }
        }
    }

    private void rectengel(int x0, int y0, int width, int height, Color color) {
        for (int x = 0; x < width; x++) {
            for (int j = 0; j < height; j++) {
                drawDot(x0 + x, j + y0, color);
            }
        }
    }


    private void zabor2(int x0, int y0, Color color) {

        for (int i = 70; i < 109; i++) {
            for (int j = 350; j < 480; j++) {
                drawDot(x0 + i, y0 + j, color);
            }
        }
    }

    private void triangle(int x0, int y0, int height, Color color) {
        for (int i = 0; i < height; i++) {
            for (int j = height; j > height - 1 - i; j--) {
                drawDot(x0 + i, y0 + j - 1, color);
            }
        }
        for (int i = 0; i < height; i++) {
            for (int j = height - 1; j > i; j--) {
                drawDot(x0 + height + i, y0 + j, color);
            }
        }
    }

    private void board(int x0, int y0, int width, int height, Color color) {
        int triangleHeight = width / 2;
        triangle(x0, y0, triangleHeight, color);
        rectengel(x0, y0 + triangleHeight, width, height - triangleHeight, color);
    }

    private void house(int x0, int y0, int width, int height) {
        int roofHeight = width / 2;

        int pipeWidth = width / 8;
        int pipeX = x0 + 3 * width / 4 - pipeWidth / 2;
        rectengel(pipeX, y0, pipeWidth, height - roofHeight, Color.red);

        triangle(x0, y0, roofHeight, Color.yellow);
        rectengel(x0, y0 + roofHeight, width, height - roofHeight, Color.gray);

        int windowHeight = width / 2;
        int wallHeight = height - roofHeight;
        rectengel(x0 + width / 4, y0 + (wallHeight - windowHeight) / 2 + roofHeight, width / 2, windowHeight, Color.white);
        rectengel(x0 + width / 4, y0 + (wallHeight - windowHeight) / 2 + roofHeight, width / 2, windowHeight, Color.white);

    }

    private void fence(int x0, int y0, int width, int height, int count, Color color) {

        for (int i = 0; i < count; i++) {
            int ggg = (width + width / 10) * i;
            board(x0 + ggg, y0, width, height, color);
        }
        int beamHeight = width / 4;
        int fenceWidth = (count * width) + (count - 1) + width / 4;
        rectengel(x0, y0 + height / 4, fenceWidth, beamHeight, color);
        rectengel(x0, y0 + height - height / 4, fenceWidth, beamHeight, color);
    }

    private void disc(int x0, int y0, int radius, Color color) {

        for (double angle = 0; angle < Math.PI; angle = angle + 0.05) {
            int x = x0 + (int) (Math.cos(angle) * radius);
            int y = y0 + (int) (Math.sin(angle) * radius);

            for (int i = y; i > y0; i--) {
                drawDot(x, i, color);
            }

            y = y0 - (int) (Math.sin(angle) * radius);
            for (int i = y; i < y0; i++) {
                drawDot(x, i, color);
            }
        }

        for (int i = x0 - radius; i < x0 + radius; i++) {
            drawDot(i, y0, color);
        }
    }


}
